home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / dev / c / CLib-SDI.lha / CLib-SDI / testsource / HookTest.c < prev    next >
C/C++ Source or Header  |  2002-10-27  |  2KB  |  78 lines

  1. /* Programmheader
  2.  
  3.     Name:        HookTest.c
  4.     Main:        example
  5.     Versionstring:    $VER: HookTest.c 1.0 (21.09.2002)
  6.     Author:        SDI
  7.     Distribution:    Freeware
  8.     Description:    the example library test program
  9.  
  10.  1.0   21.09.02 : added hook test to Test.c
  11. */
  12.  
  13. #include <utility/hooks.h>
  14. #include <proto/example.h>
  15. #include <proto/utility.h>
  16. #include <proto/dos.h>
  17. #include <proto/exec.h>
  18. #include <SDI_hook.h>
  19.  
  20. /* use global library, as this works for all compilers! */
  21. struct ExampleBase *ExampleBase = 0;
  22.  
  23. HOOKPROTO(TestHookFunc, ULONG, STRPTR object, STRPTR param)
  24. {
  25.   struct {
  26.     STRPTR a;
  27.     STRPTR b;
  28.   } CallArgs;
  29.   CallArgs.a = object;
  30.   CallArgs.b = param;
  31.   ex_TestRequest2A("Callback test",
  32.   "Your callback was called with object '%s' and param '%s'", "OK", &CallArgs);
  33.   return 5001;
  34. }
  35. MakeStaticHook(TestHook, TestHookFunc);
  36.  
  37. int main(int argc, char **argv)
  38. {
  39.   if((ExampleBase = (struct ExampleBase *) OpenLibrary("example.library", 1)))
  40.   {
  41.     ULONG callret;
  42.     ex_TestRequest("Test Message", "It really works!", "OK");
  43.  
  44.     {
  45. /* The easy method :-) When using this for the others, we would need link
  46.    libraries. */
  47. #if defined(__SASC) || defined(__STORM__) || defined(__GNUC__)
  48.       ex_TestRequest2("Test Message Number 2",
  49.       "It worked %ld times now.\n"
  50.       "You called the programm '%s' with %ld arguments", "OK",
  51.       ExampleBase->exb_NumCalls, argv[0], argc-1);
  52. #else
  53.       struct {
  54.         ULONG  a;
  55.         STRPTR b;
  56.         ULONG  c;
  57.       } CallArgs;
  58.       CallArgs.a = ExampleBase->exb_NumCalls;
  59.       CallArgs.b = argv[0];
  60.       CallArgs.c = argc-1;
  61.       ex_TestRequest2A("Test Message Number 2",
  62.       "It worked %ld times now.\n"
  63.       "You called the programm '%s' with %ld arguments", "OK", &CallArgs);
  64. #endif
  65.     }
  66.  
  67.     callret = ex_TestRequest3(&TestHook);
  68.  
  69.     ex_TestRequest2A("CallBack test",
  70.       "The callback hook returned value %ld.", "OK", &callret);
  71.  
  72.     CloseLibrary((struct Library *) ExampleBase);
  73.   }
  74.   else
  75.     Printf("Failed to open example.library\n");
  76.   return 0;
  77. }
  78.